package com.cdu.guoxinan.www.smartcom.controller;

import com.cdu.guoxinan.www.smartcom.domian.dto.ParkingSpotQueryDTO;
import com.cdu.guoxinan.www.smartcom.domian.pojo.ParkingSpot;
import com.cdu.guoxinan.www.smartcom.domian.vo.ParkingSpotVO;
import com.cdu.guoxinan.www.smartcom.service.ParkingSpotService;
import com.cdu.guoxinan.www.smartcom.unit.model.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/parkingSpot")
@Api(tags = "停车位管理控制器")
public class ParkingSpotController {

    @Resource
    private ParkingSpotService parkingSpotService;

    @GetMapping("/queryPage")
    @ApiOperation("分页查询停车位信息")
    public R queryPage(ParkingSpotQueryDTO parkingSpotQueryDTO) {
        PageInfo<ParkingSpotVO> pageInfo = parkingSpotService.queryPage(parkingSpotQueryDTO);
        return R.ok(pageInfo);
    }

    @PostMapping("/add")
    @ApiOperation("添加停车位信息")
    public R add(ParkingSpot parkingSpot) {
        return parkingSpotService.add(parkingSpot) ? R.ok("添加成功") : R.error("添加失败");
    }

    @PostMapping("/update")
    @ApiOperation("修改停车位信息")
    public R update(ParkingSpot parkingSpot) {
        return parkingSpotService.update(parkingSpot) ? R.ok("修改成功") : R.error("修改失败");
    }

    @PostMapping("/delete")
    @ApiOperation("删除停车位信息")
    public R delete(Long id) {
        return parkingSpotService.delete(id) ? R.ok("删除成功") : R.error("删除失败");
    }

    @PostMapping("/release")
    @ApiOperation("释放车位，将状态从2改为1，并删除车辆的parkingSpotId")
    public R release(ParkingSpot parkingSpot) {
        return parkingSpotService.release(parkingSpot) ? R.ok("释放成功") : R.error("释放失败");
    }
}